import {_decorator} from 'cc';
import CardsHandMgr from './CardsHandMgr';
import {CardMountainMgr} from './CardMountainMgr';
import {ManagerBase} from './ManagerBase';
import {CardPoolMgr} from './CardPoolMgr';
import {OrderPoolMgr} from './OrderPoolMgr';

const { ccclass, property } = _decorator;

@ccclass('TableMgr')
export class TableMgr extends ManagerBase {

    @property(CardMountainMgr)
    cardsMountainMgr: CardMountainMgr = null;

    @property(CardsHandMgr)
    cardsHandMgr: CardsHandMgr = null;

    /** 牌库ID */
    private _uid: string;

    get uid(): string {
        return this._uid;
    }

    protected onLoad() {
    }

    protected onEnable(): void {
        
    }

    protected onDisable(): void {
        
    }

    async initData(data: any): Promise<void> {
       
        await this.cardsMountainMgr.initData(data);
        this.cardsHandMgr.initData();
    }

    initUI(): void {
        this.cardsMountainMgr.initUI();
        this.cardsHandMgr.initUI();
    }

    refreshUI(): void {
        this.cardsMountainMgr.refreshUI();
        this.cardsHandMgr.refreshUI();
    }

    fixCard(correctCardUid: number, orderId: number) {
        let cardData = CardPoolMgr.getInstance().getCardById(correctCardUid);
        this.cardsMountainMgr.correctCard(cardData,orderId);
        this.cardsHandMgr.correctCard(cardData);
    }

    shuffle() {
        // 洗牌
        let needCardUids = OrderPoolMgr.getInstance().getNeedCards();
        const b = this.cardsMountainMgr.shuffle(needCardUids);
        if(!b){
            this.cardsHandMgr.shuffle(needCardUids);
        }
    }

    tips() :boolean{
        let needCardUids = OrderPoolMgr.getInstance().getNeedCards();
        // 提示
        let b = this.cardsMountainMgr.tips(needCardUids);
        if(!b) {
            b = this.cardsHandMgr.tips(needCardUids);
        }
        return b; 
    }


    removeCardByUid(uid) {
        this.cardsHandMgr.removeCardByUid(uid);
        this.cardsMountainMgr.removeCardByUid(uid);
    }

    showAllCards(){
        this.cardsHandMgr.showAllCards();
        this.cardsMountainMgr.showAllCards();
    }
}